// pages/index/data-bar/data-bar.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    activityCount: {
      type: Number,
      default: null,
      observer(newVal) {
        this.count = newVal;
        this.formatCount();
      },
    },
    title: {
      type: String,
      default: null,
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    nums: 0,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setNums(nums) {
      this.setData({
        nums,
      });
    },
    over() {
      this.setNums(this.count);
      clearInterval(this.timer);
    },
    formatCount() {
      if (this.timer) return;
      let _count = this.count;
      this.timer = setInterval(() => {
        let { nums } = this.data;
        if (_count < 10 || nums > 15) this.over();
        this.setNums(nums + 1);
      }, 50);
    },
  },
});
